#ifndef MY_RENDER_CAMERA
#define MY_RENDER_CAMERA

#include "../dot.hpp"
#include "../vector4.hpp"
#include "../transformation/move.hpp"
#include "../transformation/project.hpp"

namespace camera{
    class Camera{
        public :
        int right;
        int left;
        int top;
        int bottom;
        int near;
        int far;

        float fov;
        float aspect;
        float zNear;
        float zFar;

        Dot position;
        Vector4 gazeDirection;
        Vector4 upDirection;
        bool isOrthographic;

        Matrix44 MV;

        Camera(Dot position,Vector4 gazeDirection,Vector4 upDirection):position(position),gazeDirection(gazeDirection),upDirection(upDirection){}
        Camera(Dot position,Vector4 gazeDirection,Vector4 upDirection,bool isOrthographic):position(position),gazeDirection(gazeDirection),upDirection(upDirection),isOrthographic(isOrthographic){}


        // 生成mv矩阵
        void mv(){
            // 首先生成平移矩阵
            Matrix44 moveToOrigin=transformation::Move::MoveXYZ(-position.x,-position.y,-position.z);
            // 随后生成旋转视角的矩阵
            float rotateToOriginContent[16]{
                (gazeDirection^upDirection).x,(gazeDirection^upDirection).y,(gazeDirection^upDirection).z,0,
                upDirection.x,upDirection.y,upDirection.z,0,
                -gazeDirection.x,-gazeDirection.y,-gazeDirection.z,0,
                0,0,0,1
            };
            Matrix44 rotateToOrigin(rotateToOriginContent);
            MV= rotateToOrigin*moveToOrigin;
        }


        // 给相机设置视锥体
        void initCamera(int right,int left,int top,int bottom,int near,int far){
            this->right=right;
            this->left=left;
            this->top=top;
            this->bottom=bottom;
            this->near=near;
            this->far=far;
            mv();
        }
        void initCamera(float fov,float aspect,float zNear,float zFar){
            this->fov=fov;
            this->aspect=aspect;
            this->zNear=zNear;
            this->zFar=zFar;
            mv();
        }
 
 
        Camera(){};


        // 生成投影矩阵
        // 一共有两种，一种是正交，一种是透视
        Matrix44 projection(){
            if(isOrthographic){
                return transformation::Project::OrthographicProject(top,bottom,left,right,near,far);
            }
            else{
                return transformation::Project::PerspectiveProject(fov,aspect,zNear,zFar);
            }
        }

        Matrix44 MVP(){
            return projection()*MV;
        }


    };
    Camera generateCamera1();
    Camera generateCamera2();



}

#endif